package com.kye.express.business.deposit.viewholder;

import android.annotation.SuppressLint;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kye.express.App;
import com.kye.express.R;
import com.kye.express.databinding.ItemDepositConsumptionBinding;
import com.kye.model.bean.deposit.ResultDepositDetailedBean;

import me.drakeet.multitype.ItemViewBinder;

/**
 * 预存运费-消费记录 ViewHolder
 *
 * Created by SkyYu on 2018/1/17
 */
public class DepositConsumptionViewBinder extends ItemViewBinder<ResultDepositDetailedBean.DataBean, DepositConsumptionViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new ViewHolder(inflater.inflate(R.layout.item_deposit_consumption, parent, false));
    }

    @SuppressLint("StringFormatMatches")
    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull ResultDepositDetailedBean.DataBean item) {
        holder.bindData(item);
        String money = Double.toString(item.getMoney());
        if(money.equals("充值")){
            holder.textView.setText(String.format(App.getContext().getString(R.string.consumption_recharge),money));
        }else {
            // equals.("消费")
            holder.textView.setText(String.format(App.getContext().getString(R.string.consumption_consumption),money));
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private ResultDepositDetailedBean.DataBean data;
        private ItemDepositConsumptionBinding dataBinding;
        private TextView textView;

        public ViewHolder(View itemView) {
            super(itemView);
            dataBinding = DataBindingUtil.bind(itemView);
            textView = itemView.findViewById(R.id.textview_deposit_consumption_money);
        }

        public void bindData(ResultDepositDetailedBean.DataBean item) {
            data = item;
            dataBinding.setRecordModel(data);
        }
    }
}